<?php

namespace think\wework\Api;

use think\wework\Abstracts\WeworkApiWithToken;

class Invoice extends WeworkApiWithToken
{
    private static ?Invoice $instance = null;
    public static function getInstance(): Invoice
    {
        if(!self::$instance instanceof Invoice) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 查询电子发票
     *
     * @param string $id
     * @param string $code
     * @return array
     */
    public function getInfo(string $id, string $code): array
    {
        $json = ['card_id' => $id, 'encrypt_code' => $code];
        return $this->httpClient->post('card/invoice/reimburse/getinvoiceinfo', compact('json'))->toArray();
    }

    /**
     * 更新发票状态
     *
     * @param string $id
     * @param string $code
     * @param string $status
     * @return array
     */
    public function updateStatus(string $id, string $code, string $status): array
    {
        $json = ['card_id' => $id, 'encrypt_code' => $code, 'reimburse_status' => $status];
        return $this->httpClient->post('card/invoice/reimburse/updateinvoicestatus', compact('json'))->toArray();
    }

    /**
     * 批量更新发票状态
     *
     * @param string $openid
     * @param string $status
     * @param array $list
     * @return array
     */
    public function updateStatusBatch(string $openid, string $status, array $list): array
    {
        $json = [
            'openid' => $openid,
            'reimburse_status' => $status,
            'invoice_list' => $list
        ];
        return $this->httpClient->post('card/invoice/reimburse/updatestatusbatch', compact('json'))->toArray();
    }

    /**
     * 批量查询电子发票
     *
     * @param array $list
     * @return array
     */
    public function getInfoBatch(array $list): array
    {
        $json = ['item_list' => $list];
        return $this->httpClient->post('card/invoice/reimburse/getinvoiceinfobatch', compact('json'))->toArray();
    }
}
